package com.wj.hourupdate;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.view.Menu;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.TextView;

public class NewsDetailActivity extends Activity {
	private WebView newsDetailWebView;
	private TextView tvTitle;
	private ProgressBar progress;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_news_detail);
		tvTitle = (TextView) findViewById(R.id.textView1);
		progress = (ProgressBar) findViewById(R.id.progressBar1);
		newsDetailWebView = (WebView) findViewById(R.id.webView1);
		
		String strUrl = "";
		String strNewsTitle = "";
		Intent intent = getIntent();
		strUrl = intent.getStringExtra("newsUrl");
		strNewsTitle = intent.getStringExtra("newsTitle");
		
		tvTitle.setText(strNewsTitle);
		newsDetailWebView.getSettings().setJavaScriptEnabled(true);
		newsDetailWebView.setWebViewClient(new myWebClient());
		newsDetailWebView.loadUrl(strUrl);
	}

	public void onBackClicked(final View v){
		NewsDetailActivity.this.finish();
	}
	
	public class myWebClient extends WebViewClient
    {
    	@Override
    	public void onPageStarted(WebView view, String url, Bitmap favicon) {
    		// TODO Auto-generated method stub
    		super.onPageStarted(view, url, favicon);
    		
    		progress.setVisibility(View.VISIBLE);
    	}

    	@Override
    	public boolean shouldOverrideUrlLoading(WebView view, String url) {
    		// TODO Auto-generated method stub

    		view.loadUrl(url);
    		return true;

    	}

    	@Override
    	public void onPageFinished(WebView view, String url) {
    		// TODO Auto-generated method stub
    		super.onPageFinished(view, url);

    		progress.setVisibility(View.GONE);
    	}
    }
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.news_detail, menu);
		return true;
	}

}
